﻿using UnityEngine;
using System.Collections;

public class ObjectManager : MonoBehaviour {
    public SerialReader SR;

    public GameObject Obj1,Obj2,Obj3;
    string state1, state2, state3;

    public bool s11n, s11r, s11b, s12n, s12r, s12b, s13n, s13r, s13b;
    public string myString;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        
	}


    public void checkString()
    {
        if (SR.completedString != myString)
        {

            if (SR.completedString.Contains("1-3: None"))
            {
                if (s13n)
                {
                    Obj3.active = false;
                    state3 = "1-3: None";
                }
                else
                {
                    s13n = true;
                   
                }

            }
            if (SR.completedString.Contains("1-3: Blue"))
            {
                
                Obj3.active = true;
                Obj3.renderer.material.color = Color.blue;
                state3 = "1-3: Blue";
                
                  
                    s13n = false;

                    if (state1 == "1-1: Blue")
                    {
                        Obj1.active = false;
                        state1 = "1-1: None";
                    }
                    if (state2 == "1-2: Blue")
                    {
                        Obj2.active = false;
                        state2 = "1-2: None";
                    }
                
            }
            if (SR.completedString.Contains("1-3: Red"))
            {

                 Obj3.active = true;
                    Obj3.renderer.material.color = Color.red;
                    state3 = "1-3: Red";
               
                    s13n = false;


                    if (state1 == "1-1: Red")
                    {
                        Obj1.active = false;
                        state1 = "1-1: None";
                    }
                    if (state2 == "1-2: Red")
                    {
                        Obj2.active = false;
                        state2 = "1-2: None";
                    }
                
            }
            if (SR.completedString.Contains("1-2: None"))
            {
                if (s12n)
                {
                    Obj2.active = false;
                    state2 = "1-2: None";
                }
                else
                {
                    s12n = true;
                    s12r = false;
                    s12b = false;
                }

            }
            if (SR.completedString.Contains("1-2: Blue"))
            {
               
                    Obj2.active = true;
                    Obj2.renderer.material.color = Color.blue;
                    state2 = "1-2: Blue";
               
                    s12n = false;

                    if (state1 == "1-1: Blue")
                    {
                        Obj1.active = false;
                        state1 = "1-1: None";
                    }
                    if (state3 == "1-3: Blue")
                    {
                        Obj3.active = false;
                        state3 = "1-3: None";
                    }
                
            }
            if (SR.completedString.Contains("1-2: Red"))
            {

                
                    Obj2.active = true;
                    Obj2.renderer.material.color = Color.red;
                    state2 = "1-2: Red";
               
                    s12n = false;

                    if (state1 == "1-1: Red")
                    {
                        Obj1.active = false;
                        state1 = "1-1: None";
                    }
                    if (state3 == "1-3: Red")
                    {
                        Obj3.active = false;
                        state3 = "1-3: None";
                    }
                
            }


            if (SR.completedString.Contains("1-1: None"))
            {
                if (s11n)
                {
                    Obj1.active = false;
                    state1 = "1-1: None";
                }
                else
                {
                    s11n = true;
                    s11r = false;
                    s11b = false;
                }

            }
            if (SR.completedString.Contains("1-1: Blue"))
            {
                 Obj1.active = true;
                    Obj1.renderer.material.color = Color.blue;
                    state1 = "1-1: Blue";
                
                    s11n = false;


                    if (state2 == "1-2: Blue")
                    {
                        Obj2.active = false;
                        state2 = "1-2: None";
                    }
                    if (state3 == "1-3: Blue")
                    {
                        Obj3.active = false;
                        state3 = "1-3: None";
                    }
                
            }
            if (SR.completedString.Contains("1-1: Red"))
            {

                
                    Obj1.active = true;
                    Obj1.renderer.material.color = Color.red;
                    state1 = "1-1: Red";
                
                    s11n = false;

                    if (state2 == "1-2: Red")
                    {
                        Obj2.active = false;
                        state2 = "1-2: None";
                    }
                    if (state3 == "1-3: Red")
                    {
                        Obj3.active = false;
                        state3 = "1-3: None";
                    }
                
            }



        }
    }
}
